package com.rivulet.ncards;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class WordGameActivity extends AppCompatActivity {

    Button up,left,right,down;
    TextView story,information;
    Button back;
    static Integer x=0;
    static Integer y=0;
    static Integer step=0;
    static Integer speed=1;
    static Integer gift=0;
    static String mation="角色：百十一\n移动速度:";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_word_game);
        up=(Button)findViewById(R.id.up);
        left=(Button)findViewById(R.id.left);
        right=(Button)findViewById(R.id.right);
        down=(Button)findViewById(R.id.down);
        story=(TextView) findViewById(R.id.story);
        information=(TextView) findViewById(R.id.information);
        back=(Button) findViewById(R.id.word_game_back);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        story.setText("你当前在("+x+","+y+")!");
        information.setText(mation+speed+"\n积分："+gift+"\n你已移动："+step+"步");
        left.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                x-=speed;
                step+=speed;
                getGift();
                story.setText("你移动到了("+x+","+y+")!");
                information.setText(mation+speed+"\n积分："+gift+"\n你已移动："+step+"步");
                upSpeed();
                isSuccess();
            }
        });
        right.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                x+=speed;
                step+=speed;
                getGift();
                story.setText("你移动到了("+x+","+y+")!");
                information.setText(mation+speed+"\n积分："+gift+"\n你已移动："+step+"步");
                upSpeed();
                isSuccess();
            }
        });
        up.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                y+=speed;
                step+=speed;
                getGift();
                story.setText("你移动到了("+x+","+y+")!");
                information.setText(mation+speed+"\n积分："+gift+"\n你已移动："+step+"步");
                upSpeed();
                isSuccess();
            }
        });
        down.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                y-=speed;
                step+=speed ;
                getGift();
                story.setText("你移动到了("+x+","+y+")!");
                information.setText(mation+speed+"\n积分："+gift+"\n你已移动："+step+"步");
                upSpeed();
                isSuccess();
            }
        });
    }
    public void getGift(){
        if((x%5==0||y%5==0)&&(x!=0&&y!=0)){
            gift++;
        }
    }
    public void upSpeed(){
        if(speed==5){
            return;
        }
        if(x==22&&y==33){
            story.setText("你寻觅到了343,你获得了343的加持,你的移动速度现在为5");
            speed=5;
        }
    }
    public void isSuccess(){
        if(gift==49){
            story.setText("你已经获得了这个游戏的胜利，您可以退出，或者继续重复游玩！");
            x=0;
            y=0;
            speed = 1;
            step=0;
            gift=0;
        }
    }
}